//
//  BollTagLabelVC.swift
//  SwiftLearning
//
//  Created by 黄龙 on 2024/1/26.
//

import UIKit

class BollTagLabelVC: BasicNavibarVC {
    var bollView:TQQBollTagView?
    
    deinit {
        self.bollView?.stopTimer() //为免bollView里因为CADisplayLink在工作而不能deinit，在vc退出去主动关停
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.rightBar.title = ""
    }
    
    override func initView() {
        var tags:[UIButton] = []
        for i in  0 ..< 50{
           let tag = UIButton(frame: CGRect(x: 0, y: 0, width: 60, height: 25))
            tag.setTitle(String(format: "P%zd", i), for: .normal)
            tag.setTitleColor(.systemPink, for: .normal)
            tag.titleLabel?.font = .systemFont(ofSize: 24)
            tag.addActionWithBlock { [weak self](sender) in
                if let title = sender.title(for: .normal){
                    self?.rightBar.title = title
                }
                
                self?.bollView?.stopTimer()
                UIView.animate(withDuration: 0.25, delay: 0, options: [.curveEaseInOut], animations: {
                    sender.transform = CGAffineTransformMakeScale(2.0, 2.0)
                },completion:{ finished in
                    self?.bollView?.autoAnimate()
                })
            }
            tags.append(tag)
        }
        bollView = TQQBollTagView(frame: CGRect(x: 15, y: 15, width: screen_W-30, height: screen_W-30),tags: tags)
        if let bollView = bollView{
            workView.addSubview(bollView)
            bollView.autoAnimate()
        }
    }
    

}
